﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Arthus
{
    public partial class racunForma : Form
    {
        private String idPartnera, idRacuna;
        public racunForma(String partnerID, String racunID)
        {
            InitializeComponent();
            this.idPartnera = partnerID;
            this.idRacuna = racunID;
        }
        Partneri partneriObjekat = null;
        private void ProveraPostojanostiRacuna()
        {
            if (idRacuna.Length > 0)
            {
                buttonDodaj.Enabled = false;
                buttonIzmeni.Enabled = true;
            }
            else
            {
                buttonDodaj.Enabled = true;
                buttonIzmeni.Enabled = false;
            }
        }

        private void racunForma_Load(object sender, EventArgs e)
        {
            partneriObjekat = new Partneri();
            partneriObjekat.PopuniKontroleURacunFormi(idRacuna, textBoxBrojZiroRacuna, textBoxPozivNaBroj, textBoxBanka);
            ProveraPostojanostiRacuna();
        }

        private void buttonZatvori_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonDodaj_Click(object sender, EventArgs e)
        {
            partneriObjekat = new Partneri();
            partneriObjekat.DodajIliIzmeniRacun(idRacuna, idPartnera, textBoxBrojZiroRacuna, textBoxPozivNaBroj, textBoxBanka);
            textBoxBrojZiroRacuna.Text = "";
            textBoxPozivNaBroj.Text = "";
            textBoxBanka.Text = "";
            textBoxBrojZiroRacuna.Focus();
        }

        private void buttonIzmeni_Click(object sender, EventArgs e)
        {
            partneriObjekat = new Partneri();
            partneriObjekat.DodajIliIzmeniRacun(idRacuna, idPartnera, textBoxBrojZiroRacuna, textBoxPozivNaBroj, textBoxBanka);
        }

        private void TABKaoENTER(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                SelectNextControl(ActiveControl, true, true, true, true);
            }
        }
        private void textBoxBrojZiroRacuna_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxPozivNaBroj_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxBanka_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
    }
}
